//****************************************************************
// Autor:   Yimy Juarez 
//          Gustavo Castro
//          Ulil Coqti
//          Josué Barrientos
//       
// Seccion: 10
// Nombre del Archivo: Sorting.java
// Fecha de Modificacion:17/07/2012
// Descripcion:
// Crea archivo con 2000 numeros generados randomicamente
// ***************************************************************

package algoritmos;

import java.io.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public  class Archivo {
       Random numero;
       PrintStream escritor;

       Integer[] lista = new Integer[2000];
       PrintStream escritor2;
       
       public Archivo() throws FileNotFoundException
       {           
            
            numero = new Random();            

       }
       
        public void escritura(Integer[] list) throws FileNotFoundException
       {
        PrintWriter out = null;
 
        try {
            System.out.println("Entering try statement");
            out = new PrintWriter(new FileWriter("Numeros.txt"));
         
            for (int i = 0; i < 2000; i++)
                out.println(list[i].intValue());
        } catch (ArrayIndexOutOfBoundsException e) {
            System.err.println("Caught ArrayIndexOutOfBoundsException: " +
                                 e.getMessage());
        } catch (IOException e) {
            System.err.println("Caught IOException: " + e.getMessage());
        } finally {
            if (out != null) {
                System.out.println("Closing PrintWriter");
                out.close();
            } else {
                System.out.println("PrintWriter not open");
            }
        }
    }
      /**
     *
     * @throws FileNotFoundException
     */
    public void genera() throws FileNotFoundException
    {
        PrintWriter out = null;
 
        try {
            System.out.println("Entering try statement");
            out = new PrintWriter(new FileWriter("Numeros.txt"));
         
            for(int i=0;i<2000;i++)
            {
                out.println((int)(Math.random()*10000));
            }     
        } catch (ArrayIndexOutOfBoundsException e) {
            System.err.println("Caught ArrayIndexOutOfBoundsException: " +
                                 e.getMessage());
        } catch (IOException e) {
            System.err.println("Caught IOException: " + e.getMessage());
        } finally {
            if (out != null) {
                System.out.println("Closing PrintWriter");
                out.close();
            } else {
                System.out.println("PrintWriter not open");
            }
        }
    }   
    
      /**
     *
     * @throws FileNotFoundException
     * @throws IOException
     */
 
    
      
      public Integer[] lee() throws FileNotFoundException, IOException

      {
          String cadena;
          int count=0;
          BufferedReader bf = new BufferedReader(new FileReader("Numeros.txt"));
          while ((cadena = bf.readLine())!=null) {    
                lista[count]=Integer.parseInt(cadena);
                count+=1;
          } 
          return lista;
          
      }
}

